/**
 * Copyright 2010-2025 The mTASK Project Authors. All Rights Reserved.
 * Licensed under the MIT License (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.gitee.com/lort/mTask/LICENSE.md
 * Author: luyunyi @luyunyi2019@outlook.com
 */

#include <mTask.h>

int mTaskMutexInit(mTaskMutex_t *mutex)
{
    return pthread_mutex_init(mutex,NULL);
}
int mTaskMutexLock(mTaskMutex_t *mutex)
{
    return pthread_mutex_lock(mutex);
}
int mTaskMutexUnlock(mTaskMutex_t *mutex)
{
    return pthread_mutex_unlock(mutex);
}
uint64_t mTaskGetMicroSecond(void)
{
    struct timeval tv;
    struct timezone tz;
    gettimeofday(&tv,&tz);
    uint64_t temp = (tv.tv_usec/1000)+(tv.tv_sec*1000);
    return temp;
}
int mTaskSleep(int duration)
{
    usleep(duration*1000);
    return 0;
}
int mTaskRandBytes(uint8_t *bytes, int len)
{
    int i;
    srand(mTaskGetMicroSecond());
    for(i=0;i<len;i++)
    {
        bytes[i] = (uint8_t)rand();
    }
    return 0;
}
int mTaskRand(void)
{
    return rand();
}



